package com.example.demo.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.Experience;
import com.example.demo.mapper.ExperienceMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/experience")
public class ExperienceController {
    @Resource
    ExperienceMapper experienceMapper;


    @PostMapping
    public Result<?> save(@RequestBody Experience experience) {

        experienceMapper.insert(experience);
        return Result.success();

    }

    @PutMapping
    public Result<?> update(@RequestBody Experience experience) {
        experienceMapper.updateById(experience);
        return Result.success();

    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        experienceMapper.deleteById(id);
        return Result.success();

    }

    @GetMapping("/Query")
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search) {

        System.out.println("sss");
        LambdaQueryWrapper<Experience> wrapper = Wrappers.<Experience>lambdaQuery();
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(Experience::getId, search);
        }
        Page<Experience> stuPage = experienceMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        return Result.success(stuPage);

    }
    @GetMapping("/wx")
    public Result<?> experience() {

         List<Experience> experienceList = experienceMapper.selectList(null);
//        System.out.println(experienceList);
         return Result.success(experienceList);

    }

//    @PostMapping("/detail")
//    public Experience detail(@RequestBody JSONObject req) {
//        String id = req.getStr("id");
//        System.out.println("请求到了");
//        System.out.println(id);
//        Experience experience =  experienceMapper.selectById(id);
//        System.out.println(experience);
//        System.out.println("3333333333=============");
//        return experience;




}
